import request from '@/utils/request.js'
export const createGraphEditor = (params) => {
  return request({
    method: 'post',
    url: '/canvasapi/app/acomm/formOption',
    data: params
  })
}

export const getGraphCanvasPages = (params) => {
  return request({
    url: '/canvasapi/app/acomm/tableData',
    method: 'post',
    data: { pageSize: 10, pageIndex: 1, senseCode: '2OAQBA', searchFields: [{ K: 'name', V: '' }] }
  })
}
/**
 * 画布基本信息
 * @param id
 * @return {*}
 */
export const graphInfo = (id) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: { senseCode: '2OAQZT', serviceName: 'view', formFields: [{ K: 'id', V: id }] }
  })
}
/**
 * 添加画布页
 * @return {*}
 * @param canvasKey
 */
export const addCanvasPage = (canvasKey) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: { senseCode: 'GLU5TJ', serviceName: 'add', formFields: [{ K: 'canvasKey', V: canvasKey }] }
  })
}
/**
 * 删除画布页
 * @param id
 * @return {*}
 */
export const delCanvasPage = (id) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: { senseCode: 'GLU5P5', serviceName: 'del', formFields: [{ K: 'id', V: id }] }
  })
}

export const copyCanvasPage = (id) => {
  return request({
    url: '/canvasapi/app/canvas/copyCanvasPage',
    method: 'post',
    data: { senseCode: '2OAQZT', serviceName: 'copyPage', formFields: [{ K: 'id', V: id }] }
  })
}
export const sortCanvasPages = (sortId, canvasKey) => {
  return request({
    url: '/canvasapi/app/canvas/sortConvasPages',
    method: 'post',
    data: { senseCode: '2OAQZT', serviceName: 'sortPage', formFields: [{ K: 'canvasKey', V: canvasKey }, { K: 'sortId', V: sortId }] }
  })
}
export const getCanvasPages = (canvasKey) => {
  return request({
    url: '/canvasapi/app/canvas/getCanvasPages',
    method: 'post',
    data: { serviceName: 'pages', senseCode: '2OAQZT', formFields: [{ K: 'canvasKey', V: canvasKey }] }
  })
}

export const uploadFile = (params) => {
  return request({
    url: '/canvasapi/app/acomm/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: params
  })
}
export const uploadJson = (params) => {
  return request({
    url: '/canvasapi/app/canvas/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: params
  })
}
export const getCanvasPageModules = ({ canvasKey, pageCode }) => {
  return request({
    url: '/canvasapi/app/canvas/getCanvasPageModules',
    method: 'post',
    data: {
      serviceName: 'pageModules',
      senseCode: '2OAQZT',
      formFields: [
        { K: 'canvasKey', V: canvasKey },
        { K: 'pageCode', V: pageCode }
      ]
    }
  })
}

export const batchSaveModules = (data) => {
  return request({
    url: '/canvasapi/app/canvas/batchSaveModules',
    method: 'post',
    data
  })
}
// canvasapi/app/canvas/exportCanvasJson
export const exportCanvasJson = (id) => {
  return request({
    url: '/canvasapi/app/canvas/exportCanvasJson',
    method: 'post',
    responseType: 'blob',
    data: { senseCode: '2OAQZT', serviceName: 'sortPage', formFields: [{ K: 'id', V: id }] }
  })
}

export const getCanvasFonts = () => {
  return request({
    url: '/canvasapi/app/canvas/getCanvasFonts',
    method: 'post',
    data: { senseCode: '2OAQZT', serviceName: 'sortPage' }
  })
}

export const login = (data) => {
  return request({
    url: '/appucapi/sys/login',
    method: 'post',
    data
  })
}
export const getGraphList = (data) => {
  return request({
    url: '/canvasapi/app/acomm/tableData',
    method: 'post',
    data
  })
}

export const getCanvasSizeTree = (data) => {
  return request({
    url: '/canvasapi/app/canvas/getCanvasSizeTree',
    method: 'post',
    data
  })
}

export const checkGraphForm = (formFields) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: {
      senseCode: '2OAQZT',
      serviceName: 'exists',
      formFields
    }
  })
}

export const editGraphForm = (formFields, serviceName) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: {
      senseCode: '2OAQZT',
      serviceName,
      formFields
    }
  })
}
export const delGraph = (id) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: {
      senseCode: '2OAQBA',
      serviceName: 'del',
      formFields: [
        {
          K: 'id',
          V: id
        }
      ]
    }
  })
}
export const copyGraph = (id) => {
  return request({
    url: '/canvasapi/app/canvas/copyCanvas',
    method: 'post',
    data: {
      senseCode: '2OAQZT',
      serviceName: 'copy',
      formFields: [
        {
          K: 'id',
          V: id
        }
      ]
    }
  })
}

export const fontList = (data) => {
  return request({
    method: 'post',
    url: '/canvasapi/app/acomm/tableData',
    data
  })
}

/**
 * 删除字体
 * @param id
 * @return {*}
 */
export const delFont = (id) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: { senseCode: 'K75LFN', serviceName: 'del', formFields: [{ K: 'id', V: id }] }
  })
}

/**
 * 添加字体
 * @param id
 * @return {*}
 */
export const addFont = (formFields) => {
  return request({
    url: '/canvasapi/app/acomm/formOption',
    method: 'post',
    data: { senseCode: 'K75LFN', serviceName: 'add', formFields }
  })
}

export const setFontDefault = (data) => {
  return request({
    url: '/canvasapi/app/canvas/setFontDefault',
    method: 'post',
    data: data
  })
}
